package com.xw.controller.api;

import com.xw.common.Const;
import com.xw.service.IVideosInfoService;
import com.xw.util.AppUtil;
import com.xw.util.JsonData;
import com.xw.util.JsonUtil;
import com.xw.vo.VideosInfoVo;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @需求描述:课程资料
 * @创建人:whh
 * @创建时间: 2019/11/11
 * @修改需求:
 * @修改人:
 * @修改时间:
 * @需求思路:
 */
@Controller
@RequestMapping("/api/videoInfo/")
@Scope("prototype")
public class ApiVideosInfoController {

    @Resource
    private IVideosInfoService videosInfoService;

    /**
     * @需求描述:课程资料
     * @创建人:whh
     * @创建时间: 2019/11/29
     * @修改需求:
     * @修改人:
     * @修改时间:
     * @需求思路:
     */
    @RequestMapping(value = "showVideoInfo",method = RequestMethod.POST)
    @ResponseBody
    public Object showVideoInfoAction(@RequestBody Map<String,Object> paramMap) throws  Exception{
        //判断传参
        String str = AppUtil.checkIsNull(paramMap);
        if (!str.equals(Const.SUCCESS_CODE_STR)) {
            return JsonData.fail(Const.parameterError(str));
        }
        VideosInfoVo videosInfoVo = new VideosInfoVo();
        JsonUtil.mapToObject((Map<String, Object>)paramMap.get("videoInfoVo"),videosInfoVo);
        paramMap.put("videosInfoVo",videosInfoVo);

        return  videosInfoService.showVideoInfo(paramMap);
    }



    @RequestMapping(value = "downLoadVideoInfo",method = RequestMethod.POST)
    @ResponseBody
    public Object downLoadVideoInfoAction(@RequestBody Map<String,Object> paramMap) throws  Exception{
        //判断传参
        String str = AppUtil.checkIsNull(paramMap);
        if (!str.equals(Const.SUCCESS_CODE_STR)) {
            return JsonData.fail(Const.parameterError(str));
        }
        VideosInfoVo videosInfoVo = new VideosInfoVo();
        JsonUtil.mapToObject((Map<String, Object>)paramMap.get("videoInfoVo"),videosInfoVo);
        paramMap.clear();
        paramMap.put("videosInfoVo",videosInfoVo);
        paramMap.put("userId",paramMap.get("userId"));
        return  videosInfoService.downLoadVideo(paramMap);
    }

}
